package com.sxdx.service.impl;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import com.sxdx.dao.LabDAO;
import com.sxdx.entity.Laboratory;
import com.sxdx.service.LabService;

@SuppressWarnings("all")
@Service("labService")
public class LabServiceImpl implements LabService {
	private static Logger logger = LogManager.getLogger(Thread.currentThread().getStackTrace()[1].getClassName());
	@Resource(name = "labDAO")
	private LabDAO labDAO;

	public void createLab(Laboratory labcontrol) {
		labDAO.save(labcontrol);
	}

	public void deleteLab(String Id) {
		labDAO.delete(labDAO.get(Laboratory.class, Integer.parseInt(Id)));
	}

	public void orderlab(Laboratory laboratory) {
		labDAO.update(laboratory);
	}

	public Laboratory get(int Id) {
		return labDAO.get(Laboratory.class, Id);
	}

	public List<Laboratory> labInfo() {
		String hql = "from Laboratory";
		return labDAO.find(hql);
	}

	public List<Laboratory> getLab(String labName) {
		String hql = "from Laboratory l where l.labName=?";
		List<Object> param = new ArrayList<Object>();
		param.add(labName);
		return labDAO.find(hql, param);
	}

	public void changereserveclose(int labid) {
		Laboratory l = labDAO.get(Laboratory.class, labid);
		l.setReserve("0");
		labDAO.update(l);
	}

	public void changereserveopen(int labid) {
		Laboratory l = labDAO.get(Laboratory.class, labid);
		l.setReserve("1");
		labDAO.update(l);
	}
}
